package com.zhentao.equipment.controller;

import com.zhentao.equipment.service.DeviceService;
import com.zhentao.pojo.DeviceInfo;
import com.zhentao.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//import jakarta.annotation.Resource;

@RestController
@RequestMapping("/api/devices")
@CrossOrigin(origins = "*")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    @PostMapping
    public ResultVo add(@RequestBody DeviceInfo req) {
        return deviceService.add(req);
    }

    @PutMapping
    public ResultVo update(@RequestBody DeviceInfo req) {
        return deviceService.update(req);
    }

    @DeleteMapping("/{id}")
    public ResultVo delete(@PathVariable Long id) {
        return deviceService.delete(id);
    }

    @GetMapping("/{id}")
    public ResultVo detail(@PathVariable Long id) {
        return deviceService.detail(id);
    }

    @GetMapping
    public ResultVo page(@RequestParam(required = false) Integer pageNum,
                         @RequestParam(required = false) Integer pageSize,
                         @RequestParam(required = false) String deviceType,
                         @RequestParam(required = false) Integer status,
                         @RequestParam(required = false) String keyword) {
        return deviceService.page(pageNum, pageSize, deviceType, status, keyword);
    }
}





